<?php
/**
 * Created by PhpStorm.
 * User: Victor
 * Date: 2018/9/12
 * Time: 14:31
 */

namespace app\manage\controller;


use think\Controller;
use think\Request;

class Index extends BaseController
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods:POST,GET");
        header("Access-Control-Allow-Headers:x-requested-with,content-type");
        header("Content-type:text/json;charset=utf-8");
    }

    public function index()
    {
        $data = input();
        if(empty($data['username']) or empty($data['password']) ){
            $result['code']=0;
            $result['msg']=urlencode('用户名或密码为空');
            return urldecode(json_encode($result));
        }
        $password = md5($data['password']);
        $user = db('guanli')
            ->where('bh',$data['username'])
            ->where('passwd',$password)
            ->find();
        if(count($user)>0){
            $result['code']=1;
            $result['token']= base64_encode($data['username']);
            $result['msg']=urlencode('登陆成功');
            return urldecode(json_encode($result));
        }else{
            $result['code']=0;
            $result['msg']=urlencode('登录名或密码错误');
            return urldecode(json_encode($result));
        }
    }
}